<?php
/**
 * Created by PhpStorm.
 * User: edmmss
 * Date: 2019/1/9
 * Time: 14:18
 */

namespace app\modules\specification;


class AndSpecification implements SpecificationInterface
{
    private $_specifications = [];

    /**
     * AndSpecification constructor.
     * @param SpecificationInterface ...$specificationInterfaces
     */
    public function __construct(SpecificationInterface ...$specificationInterfaces)
    {
        $this->_specifications = $specificationInterfaces;
    }

    /**
     * 如果有一条规则不符合条件，返回 false，否则返回 true
     *
     * @date   2019/1/9
     * @author edmmss
     * @param Item $item
     * @return bool
     */
    public function isSatisfiedBy(Item $item): bool
    {
        // TODO: Implement isSatisfiedBy() method.
        foreach ($this->_specifications as $specification) {
            if (!$specification->isSatisfiedBy($item)) {
                return false;
            }
        }

        return true;
    }
}